#' @import methods stats utils graphics grDevices
app <- function() {
  option_list <-
    list(
         make_option(c("-i","--input.dir"),
                     metavar="<inputdir>", help="Dir which stores all .fsa files. The path is absolute path"),
         make_option(c("-o","--output.dir"),
                     metavar="<outputdir>", help="Dir which stores all result pictures"),
         make_option(c("-l","--sample.list"),
                     metavar="<sample.list>", help="A list for sample file and sample name"),
         make_option(c("-s","--samples.select"), type="character",
                     metavar="<samples.select>", help="Select samples to plot"),
         make_option(c("--ladd.init.thresh"), type="integer", default=20,
                     metavar="<ladd.init.thresh>", help="ladd init thresh to count")
         )
  options <- OptionParser(usage = "%prog -i <inputdir> -o <outputdir>", option_list = option_list)
  arguments <- parse_args(options)

  # check input.dir
  if (is.null(arguments$input.dir)) {
    cat(file = stderr(), "input.dir must be set\n")
    print_help(options)
    quit(status = -1)
  } else if (!file.exists(arguments$input.dir)) {
    cat(file = stderr(), "input.dir must exist\n")
    print_help(options)
    quit(status = -1)
  }
  # transfer input.dir to absolute path
  arguments$input.dir = normalizePath(arguments$input.dir)
  # check sample.list
  if (! is.null(arguments$sample.list)) {
    if (!file.exists(arguments$sample.list)) {
      cat(file = stderr(), "sample.list must exist\n")
      print_help(options)
      quit(status = -1)
    }
  }
  # check output.dir
  if (is.null(arguments$output.dir)) {
    arguments$output.dir = getwd()
  } else if (!file.exists(arguments$output.dir)) {
    dir.create(arguments$output.dir,recursive = TRUE)
  }
  arguments$help <- NULL

  str(arguments)
  
  do.call(pipeline_str_pic, arguments)
  #str(returnstatus)
  # step1:分析样本文件对应列表
  # step2:开始分析每组样本
  #   step2.1:生成原始文件，即把fsa文件改名,放到一个文件夹中
  #   step2.2:读取文件夹，生成需要的图片
  #   step2.3:删除step2.1生成的中间文件夹
  # 自行处理退出码
  #quit(status = 0)
}
